package pri.hillchen.std.mybatisplus.config.mybatis;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Properties;

/**
 * Created by hillchen on 2017/9/30 0030.
 */
@ConfigurationProperties(prefix = MyBatisProperties.PRI_MYBATIS_CONFIG_PREFIX)
public class MyBatisProperties {
    public static final String PRI_MYBATIS_CONFIG_PREFIX = "pri.mybatis";
    private PageHelperConfig pageHelpe;
    private String typeAliasesPackage;
    private String mapperLocations;
    private String configLocation;

    public PageHelperConfig getPageHelpe() {
        return pageHelpe;
    }

    public void setPageHelpe(PageHelperConfig pageHelpe) {
        this.pageHelpe = pageHelpe;
    }


    public String getTypeAliasesPackage() {
        return typeAliasesPackage;
    }

    public void setTypeAliasesPackage(String typeAliasesPackage) {
        this.typeAliasesPackage = typeAliasesPackage;
    }

    public String getMapperLocations() {
        return mapperLocations;
    }

    public void setMapperLocations(String mapperLocations) {
        this.mapperLocations = mapperLocations;
    }

    public String getConfigLocation() {
        return configLocation;
    }

    public void setConfigLocation(String configLocation) {
        this.configLocation = configLocation;
    }

    public static class PageHelperConfig{
        private boolean reasonable;
        private boolean supportMethodsArguments;
        private String returnPageInfo;
        private String params;

        public boolean isReasonable() {
            return reasonable;
        }

        public void setReasonable(boolean reasonable) {
            this.reasonable = reasonable;
        }

        public boolean isSupportMethodsArguments() {
            return supportMethodsArguments;
        }

        public void setSupportMethodsArguments(boolean supportMethodsArguments) {
            this.supportMethodsArguments = supportMethodsArguments;
        }

        public String getReturnPageInfo() {
            return returnPageInfo;
        }

        public void setReturnPageInfo(String returnPageInfo) {
            this.returnPageInfo = returnPageInfo;
        }

        public String getParams() {
            return params;
        }

        public void setParams(String params) {
            this.params = params;
        }

    }

    public Properties createPageHelpeProperties(){
        Properties properties = new Properties();
        if(pageHelpe != null){
            properties.setProperty("reasonable",pageHelpe.isReasonable()+"");
            properties.setProperty("supportMethodsArguments", pageHelpe.isSupportMethodsArguments()+"");
            properties.setProperty("returnPageInfo", pageHelpe.getReturnPageInfo());
            properties.setProperty("params", pageHelpe.getParams());
        }
        return properties;
    }
}
